<template>
  <div>
    <!-- 考核单审核-车厂-详情页面 -->
    <BreakSpace label="考核单信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel1" :list="formList" :cols="4" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <BaseDialog :visible.sync="selectDelearFlag" :title="'经销商选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <selectDelearPage @close="Delearclose" @save="Delearsave"></selectDelearPage>
    </BaseDialog>
    <BreakSpace label="上传视频/压缩文件" :containerStyle="{ marginBottom: '10px' }" />
    <Spin :spinning="loading" tip="Loading...">
      <FilterTable
        ref="fileTable"
        :columns="columnsFile"
        columnsRef="whbydUploadFile"
        :isSelectColumn="false"
        :onColumnsChange="columnsFile => (this.columnsFile = columnsFile)"
        height=auto
        :dataSource="list"
      />
    </Spin>
    <BreakSpace label="审核列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :dataSource="dataList"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :is-select-column="false"
      :isPagination = false
      :isSelectColumn="false"
      height="auto"
    >
    </FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <!--    <LazyLoadTab v-model="activeName" :tabMenus="menus"></LazyLoadTab>-->
    <div style="padding-top: 3rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <!--      <multiuse-button type="primary" @click="tongguo">通过</multiuse-button>-->
      <!--      <multiuse-button type="primary" @click="bohui">驳回</multiuse-button>-->
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
  import { isFormEmpty } from '@/utils/index';
  import { getPartType ,quyrPAssess} from '@/api/claim/factory/CheckSheetMaintain';
  import { dictionary } from '@/utils/dictMixin';
  export default {
    mixins: [dictionary],
    props: ['rowData'],
    components: {
    },
    data() {
      return {
        editRow: {},
        dataList: [],
        huanxiajiandataList: [],
        fujiaxiangmudataList: [],
        visible: false,
        shenHeFlag: 0,
        visibleDrawer: false,
        selectDelearFlag: false,
        collapse: false,
        infoId: null,
        flterValue: {}, //参数
        columns: this.creatHeader(),
        fetchParams: {}, //ipa 接口
        selectedRows: [], //选中经销商
        formList: this.createFormList(),
        saveData: null,
        saveData2: null,
        columnsFile: this.createdTable(),
        list: [],
      };
    },
    async created() {
      await this.chuqi();
      await this.chuqi1();
      await this.chuqi2();
      await this.getDetailFun(this.rowData.assessId);
    },
    methods: {

      //考核类型
      async chuqi() {
        // const res = await getPartType({ type: 5541 });
        // if (res.resultCode == 200) {
        //   this.formList.find(x => x.fieldName == 'assessType').initialValue = '';
        //   this.formList.find(x => x.fieldName == 'assessType').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        // }
      },
      //考核单状态
      async chuqi1() {
        // const res = await getPartType({ type: 5545 });
        // if (res.resultCode == 200) {
        //   this.formList.find(x => x.fieldName == 'assessStatus').initialValue = '';
        //   this.formList.find(x => x.fieldName == 'assessStatus').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        // }
      },
      //考核分类
      async chuqi2() {
        // const res = await getPartType({ type: 5543 });
        // if (res.resultCode == 200) {
        //   this.formList.find(x => x.fieldName == 'assessClassify').initialValue = '';
        //   this.formList.find(x => x.fieldName == 'assessClassify').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        // }
      },
      async getDetailFun(val) {
        let res= await quyrPAssess(val);
        this.editRow = res.data;
        this.$refs.fileTable.$refs.pageTable.EXECUTE_INSERT(this.editRow.fileList);
        //为form赋值
        for (let i in res.data) {
          this.formList.map(x => {
            if (x.fieldName == i) {
              x.initialValue = res.data[i];
            }
          });
        }
        //为table赋值
        if (200 == res.resultCode) {
          let data = res.data;
          if (isFormEmpty(data)) {
            data = {};
          }
          let records = data.logList;
          if (isFormEmpty(records)) {
            records = [];
          }
          this.$refs.table.$refs.pageTable.EXECUTE_INSERT(records);
        }


      },
      formChangeHandle(val) {
        this.saveData = val;
      },
      formChangeHandle2(val) {
        this.saveData2 = val;
      },
      // //搜索获取数据
      // changeHandle(val) {
      //   this.fetchParams = val;
      //   console.log(val);
      // },
      //选中
      selectChange(rows) {
        this.selectedRows = rows;
        console.log(this.selectedRows);
      },
      //取消操作
      closeDialog() {
        this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },
      //经销商选择页面
      SelectDelear() {
        this.selectDelearFlag = true;
      }, //关闭
      Delearclose() {
        this.selectDelearFlag = false;
      },
      //保存
      Delearsave(obj) {
        this.formList.map(x => {
          if ('dealerCode' == x.fieldName) {
            x.initialValue = obj[0].dealerCode;
          }
          if ('dealerName' == x.fieldName) {
            x.initialValue = obj[0].dealerName;
          }
        })

        this.selectDelearFlag = false;

      },
      chooseOrderNo() {
        this.visible = true;
      },
      add() {},
      createFormList() {
        return [
          {
            type: 'INPUT',
            label: '经销商代码',
            fieldName: 'dealerCode',
            placeholder: '请输入',
            initialValue: '',
            disabled: true // 只读
          },
          {
            type: 'INPUT',
            label: '经销商名称',
            fieldName: 'dealerName',
            disabled: true // 只读
          },
          {
            type: 'INPUT',
            label: '考核单号',
            fieldName: 'assessNo',
            disabled: true // 只读
          },
          {
            type: 'SELECT',
            label: '考核状态',
            fieldName: 'assessStatus',
            itemList: this.createDictList('5545'),
            disabled: true
          },
          {
            type: 'SELECT',
            label: '考核类型',
            fieldName: 'assessType',
            itemList: this.createDictList('5541'),
            disabled: true // 只读
          },
          {
            type: 'DATE',
            label: '考核日期',
            fieldName: 'assessDate',
            valueFormat: 'yyyy-MM-dd', //返回数据格式
            disabled: true // 只读
          },
          {
            type: 'INPUT',
            label: '考核金额',
            fieldName: 'assessAmount',
            disabled: true // 只读
          },
          {
            type: 'INPUT',
            label: '考核人员',
            fieldName: 'assessByStr',
            disabled: true // 只读
          },
          {
            type: 'SELECT',
            label: '考核分类',
            itemList: this.createDictList('5543'),
            fieldName: 'assessClassify',
            disabled: true // 只读
          },{
            type: 'INPUT',
            label: '考核原因',
            selfCols: '4',
            fieldName: 'assessReason',
            disabled: true // 只读
          },
          {
            type: 'TEXT_AREA',
            label: '备注',
            selfCols: '4',
            fieldName: 'assessRemarks',
            disabled: true // 只读
          }
        ];
      },
      createdTable() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            fixed: 'left',
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '附件标题',
            dataIndex: 'title',
            showOverflowTooltip: true,
            render: p => {
              return (
                <a style="color:#bb0a30" href={p.row.fileUrl} target="_blank" download={p.row.title}>
                  {p.row.title}
                </a>
              );
            }
          },
        ];
      },
      //table表头和数据源
      creatHeader() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          { title: '审核人', dataIndex: 'checkBy', sorter: true },
          { title: '审核时间', dataIndex: 'checkAt', sorter: true },
          { title: '审核状态', dataIndex: 'statusStr', sorter: true },
          { title: '审核原因', dataIndex: 'checkRemarks', sorter: true }
        ];
      }

    }
  };
</script>
<style lang="less" scoped></style>
